package com.example.idie.controller;

import com.example.idie.bean.Response;
import com.example.idie.service.FileUploadService;
import com.example.idie.service.UserLoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/file")
public class FileUploadController {

    @Value("${ip:localhost}")
    String ip;

    @Value("${server.port}")
    String port;


    @Autowired
    private FileUploadService fileUploadService;

    // 单文件上传
    @PostMapping("/upload")
    public Response<String> uploadSingleFile(@RequestParam("http://localhost:8080/infer")MultipartFile file) throws Exception {
        return fileUploadService.uploadSingleFile(file);
    }

    // 批量文件上传
    @PostMapping("/upload-files")
    public Response<String> uploadFiles(@RequestParam("files")MultipartFile[] file){
        return fileUploadService.uploadFiles(file);
    }

    @GetMapping("/download/{filename}")
    public Response<String> download(@PathVariable String filename, HttpServletResponse response) throws IOException{
        return fileUploadService.download(filename,response);
    }

}
